﻿using TbShop.Entity;
using PagedList;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TbShop.Business.Components
{
    public class OperationLogBC : ServiceComponents<OperationLog>, IBusinessContractBase<OperationLog>
    {
        /// <summary>
        /// 获取日志列表
        /// </summary>
        /// <param name="begin">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ope">操作类型</param>
        /// <param name="userName">用户名</param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IPagedList<OperationLog> GetPagedListBySearch(string begin, string end, string ope, List<string> userName, int pageNumber, int pageSize)
        {
            var data = this.GetAll();
            var start = DateTime.Today;
            if (!string.IsNullOrWhiteSpace(begin))
            {
                start = DateTime.Parse(begin);
            }
            data = data.Where(a => a.CreatedDate >= start);
            var endTime = DateTime.Today;
            if (!string.IsNullOrWhiteSpace(end))
            {
                endTime = DateTime.Parse(end);
            }
            endTime = endTime.AddDays(1).AddSeconds(-1);
            data = data.Where(a => a.CreatedDate <= endTime);
            if (!string.IsNullOrWhiteSpace(ope))
            {
                data = data.Where(a => a.Action == ope);
            }
            if (userName != null)
            {
                data = data.Where(a => userName.Contains(a.UserId));
            }
            return data.ToPagedList(pageNumber, pageSize);
        }
    }
}
